package cs.tongji.mad.fproj;

import android.view.KeyEvent;

public class KeyboardMapping {
	public static final int VK_LBUTTON        = 0x01;
	public static final int VK_RBUTTON        = 0x02;
	public static final int VK_CANCEL         = 0x03;
	public static final int VK_MBUTTON        = 0x04;    /* NOT contiguous with L & RBUTTON */
	public static final int VK_XBUTTON1       = 0x05;    /* NOT contiguous with L & RBUTTON */
	public static final int VK_XBUTTON2       = 0x06;    /* NOT contiguous with L & RBUTTON */
	/*
	 * = 0x07 : unassigned
	 */
	public static final int VK_BACK           = 0x08;
	public static final int VK_TAB            = 0x09;
	/*
	 * = 0x0A - = 0x0B : reserved
	 */
	public static final int VK_CLEAR          = 0x0C;
	public static final int VK_RETURN         = 0x0D;

	public static final int VK_SHIFT          = 0x10;
	public static final int VK_CONTROL        = 0x11;
	public static final int VK_MENU           = 0x12;
	public static final int VK_PAUSE          = 0x13;
	public static final int VK_CAPITAL        = 0x14;

	public static final int VK_KANA           = 0x15;
	public static final int VK_HANGEUL        = 0x15;  /* old name - should be here for compatibility */
	public static final int VK_HANGUL         = 0x15;
	public static final int VK_JUNJA          = 0x17;
	public static final int VK_FINAL          = 0x18;
	public static final int VK_HANJA          = 0x19;
	public static final int VK_KANJI          = 0x19;

	public static final int VK_ESCAPE         = 0x1B;

	public static final int VK_CONVERT        = 0x1C;
	public static final int VK_NONCONVERT     = 0x1D;
	public static final int VK_ACCEPT         = 0x1E;
	public static final int VK_MODECHANGE     = 0x1F;

	public static final int VK_SPACE          = 0x20;
	public static final int VK_PRIOR          = 0x21;
	public static final int VK_NEXT           = 0x22;
	public static final int VK_END            = 0x23;
	public static final int VK_HOME           = 0x24;
	public static final int VK_LEFT           = 0x25;
	public static final int VK_UP             = 0x26;
	public static final int VK_RIGHT          = 0x27;
	public static final int VK_DOWN           = 0x28;
	public static final int VK_SELECT         = 0x29;
	public static final int VK_PRINT          = 0x2A;
	public static final int VK_EXECUTE        = 0x2B;
	public static final int VK_SNAPSHOT       = 0x2C;
	public static final int VK_INSERT         = 0x2D;
	public static final int VK_DELETE         = 0x2E;
	public static final int VK_HELP           = 0x2F;

	/*
	 * VK_0 - VK_9 are the same as ASCII '0' - '9' (= 0x30 - = 0x39)
	 * = 0x40 : unassigned
	 * VK_A - VK_Z are the same as ASCII 'A' - 'Z' (= 0x41 - = 0x5A)
	 */

	public static final int VK_LWIN           = 0x5B;
	public static final int VK_RWIN           = 0x5C;
	public static final int VK_APPS           = 0x5D;

	/*
	 * = 0x5E : reserved
	 */

	public static final int VK_SLEEP          = 0x5F;

	public static final int VK_NUMPAD0        = 0x60;
	public static final int VK_NUMPAD1        = 0x61;
	public static final int VK_NUMPAD2        = 0x62;
	public static final int VK_NUMPAD3        = 0x63;
	public static final int VK_NUMPAD4        = 0x64;
	public static final int VK_NUMPAD5        = 0x65;
	public static final int VK_NUMPAD6        = 0x66;
	public static final int VK_NUMPAD7        = 0x67;
	public static final int VK_NUMPAD8        = 0x68;
	public static final int VK_NUMPAD9        = 0x69;
	public static final int VK_MULTIPLY       = 0x6A;
	public static final int VK_ADD            = 0x6B;
	public static final int VK_SEPARATOR      = 0x6C;
	public static final int VK_SUBTRACT       = 0x6D;
	public static final int VK_DECIMAL        = 0x6E;
	public static final int VK_DIVIDE         = 0x6F;
	public static final int VK_F1             = 0x70;
	public static final int VK_F2             = 0x71;
	public static final int VK_F3             = 0x72;
	public static final int VK_F4             = 0x73;
	public static final int VK_F5             = 0x74;
	public static final int VK_F6             = 0x75;
	public static final int VK_F7             = 0x76;
	public static final int VK_F8             = 0x77;
	public static final int VK_F9             = 0x78;
	public static final int VK_F10            = 0x79;
	public static final int VK_F11            = 0x7A;
	public static final int VK_F12            = 0x7B;
	public static final int VK_F13            = 0x7C;
	public static final int VK_F14            = 0x7D;
	public static final int VK_F15            = 0x7E;
	public static final int VK_F16            = 0x7F;
	public static final int VK_F17            = 0x80;
	public static final int VK_F18            = 0x81;
	public static final int VK_F19            = 0x82;
	public static final int VK_F20            = 0x83;
	public static final int VK_F21            = 0x84;
	public static final int VK_F22            = 0x85;
	public static final int VK_F23            = 0x86;
	public static final int VK_F24            = 0x87;

	/*
	 * = 0x88 - = 0x8F : unassigned
	 */

	public static final int VK_NUMLOCK        = 0x90;
	public static final int VK_SCROLL         = 0x91;

	/*
	 * NEC PC-9800 kbd definitions
	 */
	public static final int VK_OEM_NEC_EQUAL  = 0x92;  // '=' key on numpad

	/*
	 * Fujitsu/OASYS kbd definitions
	 */
	public static final int VK_OEM_FJ_JISHO   = 0x92;   // 'Dictionary' key
	public static final int VK_OEM_FJ_MASSHOU = 0x93;   // 'Unregister word' key
	public static final int VK_OEM_FJ_TOUROKU = 0x94;   // 'Register word' key
	public static final int VK_OEM_FJ_LOYA    = 0x95;   // 'Left OYAYUBI' key
	public static final int VK_OEM_FJ_ROYA    = 0x96;   // 'Right OYAYUBI' key

	/*
	 * = 0x97 - = 0x9F : unassigned
	 */

	/*
	 * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
	 * Used only as parameters to GetAsyncKeyState() and GetKeyState().
	 * No other API or message will distinguish left and right keys in this way.
	 */
	public static final int VK_LSHIFT         = 0xA0;
	public static final int VK_RSHIFT         = 0xA1;
	public static final int VK_LCONTROL       = 0xA2;
	public static final int VK_RCONTROL       = 0xA3;
	public static final int VK_LMENU          = 0xA4;
	public static final int VK_RMENU          = 0xA5;

	public static final int VK_BROWSER_BACK        = 0xA6;
	public static final int VK_BROWSER_FORWARD     = 0xA7;
	public static final int VK_BROWSER_REFRESH     = 0xA8;
	public static final int VK_BROWSER_STOP        = 0xA9;
	public static final int VK_BROWSER_SEARCH      = 0xAA;
	public static final int VK_BROWSER_FAVORITES   = 0xAB;
	public static final int VK_BROWSER_HOME        = 0xAC;

	public static final int VK_VOLUME_MUTE         = 0xAD;
	public static final int VK_VOLUME_DOWN         = 0xAE;
	public static final int VK_VOLUME_UP           = 0xAF;
	public static final int VK_MEDIA_NEXT_TRACK    = 0xB0;
	public static final int VK_MEDIA_PREV_TRACK    = 0xB1;
	public static final int VK_MEDIA_STOP          = 0xB2;
	public static final int VK_MEDIA_PLAY_PAUSE    = 0xB3;
	public static final int VK_LAUNCH_MAIL         = 0xB4;
	public static final int VK_LAUNCH_MEDIA_SELECT = 0xB5;
	public static final int VK_LAUNCH_APP1         = 0xB6;
	public static final int VK_LAUNCH_APP2         = 0xB7;


	/*
	 * = 0xB8 - = 0xB9 : reserved
	 */

	public static final int VK_OEM_1          = 0xBA;   // ';:' for US
	public static final int VK_OEM_PLUS       = 0xBB;   // '+' any country
	public static final int VK_OEM_COMMA      = 0xBC;   // ',' any country
	public static final int VK_OEM_MINUS      = 0xBD;   // '-' any country
	public static final int VK_OEM_PERIOD     = 0xBE;   // '.' any country
	public static final int VK_OEM_2          = 0xBF;   // '/?' for US
	public static final int VK_OEM_3          = 0xC0;   // '`~' for US

	/*
	 * = 0xC1 - = 0xD7 : reserved
	 */

	/*
	 * = 0xD8 - = 0xDA : unassigned
	 */

	public static final int VK_OEM_4          = 0xDB;  //  '[{' for US
	public static final int VK_OEM_5          = 0xDC;  //  '\|' for US
	public static final int VK_OEM_6          = 0xDD;  //  ']}' for US
	public static final int VK_OEM_7          = 0xDE;  //  ''"' for US
	public static final int VK_OEM_8          = 0xDF;

	/*
	 * = 0xE0 : reserved
	 */

	/*
	 * Various extended or enhanced keyboards
	 */
	public static final int VK_OEM_AX         = 0xE1;  //  'AX' key on Japanese AX kbd
	public static final int VK_OEM_102        = 0xE2;  //  "<>" or "\|" on RT 102-key kbd.
	public static final int VK_ICO_HELP       = 0xE3;  //  Help key on ICO
	public static final int VK_ICO_00         = 0xE4;  //  00 key on ICO

	public static final int VK_PROCESSKEY     = 0xE5;

	public static final int VK_ICO_CLEAR      = 0xE6;

	public static final int VK_PACKET         = 0xE7;

	/*
	 * = 0xE8 : unassigned
	 */

	/*
	 * Nokia/Ericsson definitions
	 */
	public static final int VK_OEM_RESET      = 0xE9;
	public static final int VK_OEM_JUMP       = 0xEA;
	public static final int VK_OEM_PA1        = 0xEB;
	public static final int VK_OEM_PA2        = 0xEC;
	public static final int VK_OEM_PA3        = 0xED;
	public static final int VK_OEM_WSCTRL     = 0xEE;
	public static final int VK_OEM_CUSEL      = 0xEF;
	public static final int VK_OEM_ATTN       = 0xF0;
	public static final int VK_OEM_FINISH     = 0xF1;
	public static final int VK_OEM_COPY       = 0xF2;
	public static final int VK_OEM_AUTO       = 0xF3;
	public static final int VK_OEM_ENLW       = 0xF4;
	public static final int VK_OEM_BACKTAB    = 0xF5;

	public static final int VK_ATTN           = 0xF6;
	public static final int VK_CRSEL          = 0xF7;
	public static final int VK_EXSEL          = 0xF8;
	public static final int VK_EREOF          = 0xF9;
	public static final int VK_PLAY           = 0xFA;
	public static final int VK_ZOOM           = 0xFB;
	public static final int VK_NONAME         = 0xFC;
	public static final int VK_PA1            = 0xFD;
	public static final int VK_OEM_CLEAR      = 0xFE;
	
	private int androidKeyToWindowsVirtual [];
	
	private KeyboardMapping()
	{
		androidKeyToWindowsVirtual = new int [256];
		
		
		androidKeyToWindowsVirtual[KeyEvent.KEYCODE_UNKNOWN] = 0;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_SOFT_LEFT] = VK_LBUTTON;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_SOFT_RIGHT] = VK_RBUTTON;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_HOME] = VK_HOME;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_BACK] = 0;//VK_BACK;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_CALL] = VK_RETURN;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_ENDCALL] = VK_RETURN;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_0] = '0';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_1] = '1';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_2] = '2';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_3] = '3';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_4] = '4';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_5] = '5';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_6] = '6';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_7] = '7';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_8] = '8';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_9] = '9';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_STAR] = 0;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_POUND] = 0;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_DPAD_UP] = VK_UP;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_DPAD_DOWN] = VK_DOWN;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_DPAD_LEFT] = VK_LEFT;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_DPAD_RIGHT] = VK_RIGHT;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_DPAD_CENTER] = VK_RETURN;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_VOLUME_UP] = VK_VOLUME_UP;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_VOLUME_DOWN] = VK_VOLUME_DOWN;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_POWER] = 0;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_CAMERA] = 0;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_CLEAR] = VK_CLEAR;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_A] = 'A';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_B] = 'B';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_C] = 'C';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_D] = 'D';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_E] = 'E';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_F] = 'F';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_G] = 'G';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_H] = 'H';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_I] = 'I';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_J] = 'J';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_K] = 'K';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_L] = 'L';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_M] = 'M';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_N] = 'N';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_O] = 'O';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_P] = 'P';


		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_Q] = 'Q';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_R] = 'R';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_S] = 'S';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_T] = 'T';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_U] = 'U';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_V] = 'V';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_W] = 'W';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_X] = 'X';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_Y] = 'Y';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_Z] = 'Z';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_COMMA] = VK_OEM_COMMA;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_PERIOD] = VK_OEM_PERIOD;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_ALT_LEFT] = VK_LMENU;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_ALT_RIGHT] = VK_RMENU;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_SHIFT_LEFT] = VK_LSHIFT;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_SHIFT_RIGHT] = VK_RSHIFT;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_TAB] = VK_TAB;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_SPACE] = VK_SPACE;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_SYM] = 0;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_EXPLORER] = VK_BROWSER_HOME;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_ENVELOPE] = VK_LAUNCH_MAIL;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_ENTER] = VK_RETURN;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_DEL] = VK_DELETE;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_GRAVE] = VK_OEM_3;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_MINUS] = VK_OEM_MINUS;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_EQUALS] = VK_OEM_PLUS;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_LEFT_BRACKET] = VK_OEM_4;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_RIGHT_BRACKET] = VK_OEM_6;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_BACKSLASH] = VK_OEM_5;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_SEMICOLON] = VK_OEM_1;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_APOSTROPHE] = VK_OEM_7;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_SLASH] = VK_OEM_2;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_AT] = '2';
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_NUM] = VK_NUMLOCK;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_HEADSETHOOK] = 0;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_FOCUS] = 0;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_PLUS] = VK_OEM_PLUS;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_MENU] = 0;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_NOTIFICATION] = 0;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_SEARCH] = VK_BROWSER_SEARCH;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE] = VK_MEDIA_PLAY_PAUSE;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_MEDIA_STOP] = VK_MEDIA_STOP;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_MEDIA_NEXT] = VK_MEDIA_NEXT_TRACK;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_MEDIA_PREVIOUS] = VK_MEDIA_PREV_TRACK;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_MEDIA_REWIND] = VK_LAUNCH_MEDIA_SELECT;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_MEDIA_FAST_FORWARD] = VK_LAUNCH_MEDIA_SELECT;
		  
		  
		  androidKeyToWindowsVirtual[KeyEvent.KEYCODE_MUTE] = VK_VOLUME_MUTE;
	}
	
	private static KeyboardMapping instance = new KeyboardMapping();
	
	public KeyboardMapping getInstance() {
		return instance;
	}
	
	public static int mapAndroidKeyToWindowsVirtual(int androidKey) {
		return instance.androidKeyToWindowsVirtual[androidKey];
	}
	
}
